using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the StatsTracker class.
	/// </summary>
	[Serializable]
	public partial class StatsTrackerCollection : ActiveList<StatsTracker,StatsTrackerCollection> 
	{	   
		public StatsTrackerCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Stats_Tracker table.
	/// </summary>
	[Serializable]
	public partial class StatsTracker : ActiveRecord<StatsTracker>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public StatsTracker()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public StatsTracker(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public StatsTracker(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public StatsTracker(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Stats_Tracker", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarTrackingID = new TableSchema.TableColumn(schema);
				colvarTrackingID.ColumnName = "trackingID";
				colvarTrackingID.DataType = DbType.Int32;
				colvarTrackingID.MaxLength = 0;
				colvarTrackingID.AutoIncrement = true;
				colvarTrackingID.IsNullable = false;
				colvarTrackingID.IsPrimaryKey = true;
				colvarTrackingID.IsForeignKey = false;
				colvarTrackingID.IsReadOnly = false;
				colvarTrackingID.DefaultSetting = @"";
				colvarTrackingID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTrackingID);
				
				TableSchema.TableColumn colvarUserName = new TableSchema.TableColumn(schema);
				colvarUserName.ColumnName = "userName";
				colvarUserName.DataType = DbType.String;
				colvarUserName.MaxLength = 50;
				colvarUserName.AutoIncrement = false;
				colvarUserName.IsNullable = false;
				colvarUserName.IsPrimaryKey = false;
				colvarUserName.IsForeignKey = false;
				colvarUserName.IsReadOnly = false;
				colvarUserName.DefaultSetting = @"";
				colvarUserName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserName);
				
				TableSchema.TableColumn colvarAdID = new TableSchema.TableColumn(schema);
				colvarAdID.ColumnName = "adID";
				colvarAdID.DataType = DbType.Int32;
				colvarAdID.MaxLength = 0;
				colvarAdID.AutoIncrement = false;
				colvarAdID.IsNullable = true;
				colvarAdID.IsPrimaryKey = false;
				colvarAdID.IsForeignKey = false;
				colvarAdID.IsReadOnly = false;
				colvarAdID.DefaultSetting = @"";
				colvarAdID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdID);
				
				TableSchema.TableColumn colvarPromoID = new TableSchema.TableColumn(schema);
				colvarPromoID.ColumnName = "promoID";
				colvarPromoID.DataType = DbType.Int32;
				colvarPromoID.MaxLength = 0;
				colvarPromoID.AutoIncrement = false;
				colvarPromoID.IsNullable = true;
				colvarPromoID.IsPrimaryKey = false;
				colvarPromoID.IsForeignKey = false;
				colvarPromoID.IsReadOnly = false;
				colvarPromoID.DefaultSetting = @"";
				colvarPromoID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPromoID);
				
				TableSchema.TableColumn colvarProductSKU = new TableSchema.TableColumn(schema);
				colvarProductSKU.ColumnName = "productSKU";
				colvarProductSKU.DataType = DbType.String;
				colvarProductSKU.MaxLength = 50;
				colvarProductSKU.AutoIncrement = false;
				colvarProductSKU.IsNullable = true;
				colvarProductSKU.IsPrimaryKey = false;
				colvarProductSKU.IsForeignKey = false;
				colvarProductSKU.IsReadOnly = false;
				colvarProductSKU.DefaultSetting = @"";
				colvarProductSKU.ForeignKeyTableName = "";
				schema.Columns.Add(colvarProductSKU);
				
				TableSchema.TableColumn colvarCategoryID = new TableSchema.TableColumn(schema);
				colvarCategoryID.ColumnName = "categoryID";
				colvarCategoryID.DataType = DbType.Int32;
				colvarCategoryID.MaxLength = 0;
				colvarCategoryID.AutoIncrement = false;
				colvarCategoryID.IsNullable = true;
				colvarCategoryID.IsPrimaryKey = false;
				colvarCategoryID.IsForeignKey = false;
				colvarCategoryID.IsReadOnly = false;
				colvarCategoryID.DefaultSetting = @"";
				colvarCategoryID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryID);
				
				TableSchema.TableColumn colvarPageURL = new TableSchema.TableColumn(schema);
				colvarPageURL.ColumnName = "pageURL";
				colvarPageURL.DataType = DbType.String;
				colvarPageURL.MaxLength = 100;
				colvarPageURL.AutoIncrement = false;
				colvarPageURL.IsNullable = true;
				colvarPageURL.IsPrimaryKey = false;
				colvarPageURL.IsForeignKey = false;
				colvarPageURL.IsReadOnly = false;
				colvarPageURL.DefaultSetting = @"";
				colvarPageURL.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPageURL);
				
				TableSchema.TableColumn colvarBehaviorID = new TableSchema.TableColumn(schema);
				colvarBehaviorID.ColumnName = "behaviorID";
				colvarBehaviorID.DataType = DbType.Int32;
				colvarBehaviorID.MaxLength = 0;
				colvarBehaviorID.AutoIncrement = false;
				colvarBehaviorID.IsNullable = false;
				colvarBehaviorID.IsPrimaryKey = false;
				colvarBehaviorID.IsForeignKey = true;
				colvarBehaviorID.IsReadOnly = false;
				colvarBehaviorID.DefaultSetting = @"";
				
					colvarBehaviorID.ForeignKeyTableName = "CSK_Stats_Behavior";
				schema.Columns.Add(colvarBehaviorID);
				
				TableSchema.TableColumn colvarSearchString = new TableSchema.TableColumn(schema);
				colvarSearchString.ColumnName = "searchString";
				colvarSearchString.DataType = DbType.String;
				colvarSearchString.MaxLength = 150;
				colvarSearchString.AutoIncrement = false;
				colvarSearchString.IsNullable = true;
				colvarSearchString.IsPrimaryKey = false;
				colvarSearchString.IsForeignKey = false;
				colvarSearchString.IsReadOnly = false;
				colvarSearchString.DefaultSetting = @"";
				colvarSearchString.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSearchString);
				
				TableSchema.TableColumn colvarSessionID = new TableSchema.TableColumn(schema);
				colvarSessionID.ColumnName = "sessionID";
				colvarSessionID.DataType = DbType.String;
				colvarSessionID.MaxLength = 50;
				colvarSessionID.AutoIncrement = false;
				colvarSessionID.IsNullable = true;
				colvarSessionID.IsPrimaryKey = false;
				colvarSessionID.IsForeignKey = false;
				colvarSessionID.IsReadOnly = false;
				colvarSessionID.DefaultSetting = @"";
				colvarSessionID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSessionID);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "createdOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "createdBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "modifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "modifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Stats_Tracker",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("TrackingID")]
		public int TrackingID 
		{
			get { return GetColumnValue<int>(Columns.TrackingID); }

			set { SetColumnValue(Columns.TrackingID, value); }

		}

		  
		[XmlAttribute("UserName")]
		public string UserName 
		{
			get { return GetColumnValue<string>(Columns.UserName); }

			set { SetColumnValue(Columns.UserName, value); }

		}

		
		
		//private int? propAdID;
		[XmlAttribute("AdID")]
		public int AdID 
		{
			get
			{
			int? propAdID = GetColumnValue<int?>(Columns.AdID);
				if (!propAdID.HasValue)
					return 0;
				return propAdID.Value;
			}

		   set { SetColumnValue(Columns.AdID, value); }

		}

		
		[XmlIgnore]
		public bool AdIDHasValue
		{
			get { return GetColumnValue<int?>("adID") != null; }

			set
			{
				int? propAdID = GetColumnValue<int?>(Columns.AdID);
				if (!value)
					SetColumnValue(Columns.AdID, null);
				else if (value && !propAdID.HasValue)
					SetColumnValue(Columns.AdID, 0);
		   }

		}

		
		
		
		//private int? propPromoID;
		[XmlAttribute("PromoID")]
		public int PromoID 
		{
			get
			{
			int? propPromoID = GetColumnValue<int?>(Columns.PromoID);
				if (!propPromoID.HasValue)
					return 0;
				return propPromoID.Value;
			}

		   set { SetColumnValue(Columns.PromoID, value); }

		}

		
		[XmlIgnore]
		public bool PromoIDHasValue
		{
			get { return GetColumnValue<int?>("promoID") != null; }

			set
			{
				int? propPromoID = GetColumnValue<int?>(Columns.PromoID);
				if (!value)
					SetColumnValue(Columns.PromoID, null);
				else if (value && !propPromoID.HasValue)
					SetColumnValue(Columns.PromoID, 0);
		   }

		}

		
		  
		[XmlAttribute("ProductSKU")]
		public string ProductSKU 
		{
			get { return GetColumnValue<string>(Columns.ProductSKU); }

			set { SetColumnValue(Columns.ProductSKU, value); }

		}

		
		
		//private int? propCategoryID;
		[XmlAttribute("CategoryID")]
		public int CategoryID 
		{
			get
			{
			int? propCategoryID = GetColumnValue<int?>(Columns.CategoryID);
				if (!propCategoryID.HasValue)
					return 0;
				return propCategoryID.Value;
			}

		   set { SetColumnValue(Columns.CategoryID, value); }

		}

		
		[XmlIgnore]
		public bool CategoryIDHasValue
		{
			get { return GetColumnValue<int?>("categoryID") != null; }

			set
			{
				int? propCategoryID = GetColumnValue<int?>(Columns.CategoryID);
				if (!value)
					SetColumnValue(Columns.CategoryID, null);
				else if (value && !propCategoryID.HasValue)
					SetColumnValue(Columns.CategoryID, 0);
		   }

		}

		
		  
		[XmlAttribute("PageURL")]
		public string PageURL 
		{
			get { return GetColumnValue<string>(Columns.PageURL); }

			set { SetColumnValue(Columns.PageURL, value); }

		}

		  
		[XmlAttribute("BehaviorID")]
		public int BehaviorID 
		{
			get { return GetColumnValue<int>(Columns.BehaviorID); }

			set { SetColumnValue(Columns.BehaviorID, value); }

		}

		  
		[XmlAttribute("SearchString")]
		public string SearchString 
		{
			get { return GetColumnValue<string>(Columns.SearchString); }

			set { SetColumnValue(Columns.SearchString, value); }

		}

		  
		[XmlAttribute("SessionID")]
		public string SessionID 
		{
			get { return GetColumnValue<string>(Columns.SessionID); }

			set { SetColumnValue(Columns.SessionID, value); }

		}

		
		
		//private DateTime? propCreatedOn;
		[XmlAttribute("CreatedOn")]
		public DateTime CreatedOn 
		{
			get
			{
			DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!propCreatedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propCreatedOn.Value;
			}

		   set { SetColumnValue(Columns.CreatedOn, value); }

		}

		
		[XmlIgnore]
		public bool CreatedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("createdOn") != null; }

			set
			{
				DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!value)
					SetColumnValue(Columns.CreatedOn, null);
				else if (value && !propCreatedOn.HasValue)
					SetColumnValue(Columns.CreatedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }

			set { SetColumnValue(Columns.CreatedBy, value); }

		}

		
		
		//private DateTime? propModifiedOn;
		[XmlAttribute("ModifiedOn")]
		public DateTime ModifiedOn 
		{
			get
			{
			DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!propModifiedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propModifiedOn.Value;
			}

		   set { SetColumnValue(Columns.ModifiedOn, value); }

		}

		
		[XmlIgnore]
		public bool ModifiedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("modifiedOn") != null; }

			set
			{
				DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!value)
					SetColumnValue(Columns.ModifiedOn, null);
				else if (value && !propModifiedOn.HasValue)
					SetColumnValue(Columns.ModifiedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>(Columns.ModifiedBy); }

			set { SetColumnValue(Columns.ModifiedBy, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a StatsBehavior ActiveRecord object related to this StatsTracker
		/// 
		/// </summary>
		public Commerce.Common.StatsBehavior StatsBehavior
		{
			get { return Commerce.Common.StatsBehavior.FetchByID(this.BehaviorID); }

			set { SetColumnValue("behaviorID", value.BehaviorID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varUserName,int varAdID,int varPromoID,string varProductSKU,int varCategoryID,string varPageURL,int varBehaviorID,string varSearchString,string varSessionID,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			StatsTracker item = new StatsTracker();
			
			item.UserName = varUserName;
			
			item.AdID = varAdID;
			
			item.PromoID = varPromoID;
			
			item.ProductSKU = varProductSKU;
			
			item.CategoryID = varCategoryID;
			
			item.PageURL = varPageURL;
			
			item.BehaviorID = varBehaviorID;
			
			item.SearchString = varSearchString;
			
			item.SessionID = varSessionID;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varTrackingID,string varUserName,int varAdID,int varPromoID,string varProductSKU,int varCategoryID,string varPageURL,int varBehaviorID,string varSearchString,string varSessionID,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			StatsTracker item = new StatsTracker();
			
				item.TrackingID = varTrackingID;
			
				item.UserName = varUserName;
			
				item.AdID = varAdID;
			
				item.PromoID = varPromoID;
			
				item.ProductSKU = varProductSKU;
			
				item.CategoryID = varCategoryID;
			
				item.PageURL = varPageURL;
			
				item.BehaviorID = varBehaviorID;
			
				item.SearchString = varSearchString;
			
				item.SessionID = varSessionID;
			
				item.CreatedOn = varCreatedOn;
			
				item.CreatedBy = varCreatedBy;
			
				item.ModifiedOn = varModifiedOn;
			
				item.ModifiedBy = varModifiedBy;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn TrackingIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn UserNameColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn AdIDColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn PromoIDColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn ProductSKUColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn CategoryIDColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn PageURLColumn
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        public static TableSchema.TableColumn BehaviorIDColumn
        {
            get { return Schema.Columns[7]; }

        }

        
        
        
        public static TableSchema.TableColumn SearchStringColumn
        {
            get { return Schema.Columns[8]; }

        }

        
        
        
        public static TableSchema.TableColumn SessionIDColumn
        {
            get { return Schema.Columns[9]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[10]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[11]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedOnColumn
        {
            get { return Schema.Columns[12]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedByColumn
        {
            get { return Schema.Columns[13]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string TrackingID = @"trackingID";
			 public static string UserName = @"userName";
			 public static string AdID = @"adID";
			 public static string PromoID = @"promoID";
			 public static string ProductSKU = @"productSKU";
			 public static string CategoryID = @"categoryID";
			 public static string PageURL = @"pageURL";
			 public static string BehaviorID = @"behaviorID";
			 public static string SearchString = @"searchString";
			 public static string SessionID = @"sessionID";
			 public static string CreatedOn = @"createdOn";
			 public static string CreatedBy = @"createdBy";
			 public static string ModifiedOn = @"modifiedOn";
			 public static string ModifiedBy = @"modifiedBy";
						
		}

		#endregion
		
		
		
	}

}

